package utils 
{
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author jun
	 */
	public class HashMap
	{
		private var content:Dictionary ;
		private var length:uint;
		
		public function HashMap() 
		{
			content = new Dictionary();
			length = 0;
		}
		
		public function get(key:*):* 
		{
			return content[key];
		}
		
		public function keys():Array
		{
			var arr:Array = [];
			for (var key:* in content)
			{
				arr.push(key);
			}
			return arr;
		}
		
		public function values():Array
		{
			var team:Array = new Array(length);
			var index:uint = 0;
			for each(var v:* in content)
			{
				team[index] = v;
				index++;
			}
			return team;
		}
		
		public function contains(value:*):Boolean
		{
			for each(var v:* in content)
			{
				if (v === value)
					return true;
			}
			return false;
		}
		
		public function containsKey(key:*):Boolean
		{
			return (keys().indexOf(key) >= 0)? true:false;
		}
		
		public function put(key:*, value:*):*
		{
			if (value == null)
			{
				delete content[key];
				return undefined;
			}
			else
			{
				if (!containsKey(key))//如果原先没有该key
				{
					length++;
				}
				content[key] = value;
			}
		}
		
		public function remove(key:*):*
		{
			var temp:*;
			if (containsKey(key))
			{
				temp = get(key);
				delete content[key];
				length--;
				return temp;
			}
			return null;
		}
		
		public function size():int 
		{
			return length;
		}
		
		public function clear():void 
		{
			length = 0;
			content = new Dictionary();
		}
		
		public function isEmpty():Boolean 
		{
			return Boolean(length);
		}
	}

}